<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>联盟详情</title>
    <script src="../js/mui.min.js"></script>
	<link href="../css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="../css/style.css" />
	<link rel="stylesheet" href="../css/iconfont.css" />
	<link rel="stylesheet" href="../css/sjhout.css" />
    <script type="text/javascript" charset="utf-8">
      	mui.init();
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">联盟详情</h1>
	</header>
	<div class="mui-content recharge_content" style="height: auto;">
		<ul class="myshop_lsdedit alliance_edit">
			<li class="clearfix">
				<div class="left">LOGO：</div>
				<div class="toux"><img src="../images/moren.jpg" id='union_logo'></div>
			</li>
			<li class="clearfix">
				<div class="left">联盟名称：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='chain_name' id='chain_name'>
			</li>
			<li class="clearfix">
				<div class="left">联盟主：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='store_name' id='store_name'>
			</li>
			<li class="clearfix">
				<div class="left">手机号码：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='chain_mobile' id='chain_mobile'>
			</li>
			<li class="clearfix">
				<div class="left">单客次广告费：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='chain_diz' id='chain_diz'>
			</li>
			<li class="clearfix">
				<div class="left">描述：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='chain_content' id='chain_content'>
			</li>
			<li class="clearfix">
				<div class="left">经营范围：</div>
				<input class="right clearfix" type="text" readonly="true" placeholder="" name='chain_user' id='chain_user'>
			</li>
		</ul>
		<button type="button" class="chongz_btn" id='union_apply'  style="display: none;">申请加入</button>
		<button type="button" class="chongz_btn" id='apply_state'  style="display: none;">已加入,审核中..</button>
		<button type="button" class="chongz_btn" id='union_state'  style="display: none;">已申请,平台审核中..</button>
		<button type="button" class="chongz_btn" id='union_item'  style="display: none;">成员列表</button>
		<button type="button" class="chongz_btn" id="item_manage"  style="display: none;">成员管理</button>		
		<button type="button" class="chongz_btn" id='back_union' style="display: none;">退出联盟</button>
		<button type="button" class="chongz_btn" id='back_union_main' style="display: none;">退出联盟</button>
		<input type="hidden" id='cut_agent_id'>
	</div>
</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function(){
		var union_id = getUrlParam("union_id");
		$.ajax({
			url: APP.api_url + 'wallet/union_info_by_id',
			data: {
				token		: get_token(),
				uid			: getUid(),
				union_id	: union_id
			},
			success: function(data) {
				if(data.code == 200) {
					var agent_info = data.data.agent_info;
					var union_info = data.data.union_info;
					var in_this_union = data.data.in_this_union;
					var in_apply = data.data.in_apply;
					//保存当前店铺信息
					$('#cut_agent_id').val(agent_info['id']);
					//图片地址
					var touxiang = user_tupian(union_info['thumb'],'../images/toux.jpg');
					//头像
					$('#union_logo').attr('src',touxiang);
					//联盟名称
					$('#chain_name').val(union_info.name);
					//联盟主
					$('#store_name').val(union_info.store_name);
					//手机号码
					$('#chain_diz').val(union_info.tel);
					//单客次广告费
					$('#chain_diz').val(union_info.unnion_ads_money);
					//联盟范围
					$('#chain_user').val(union_info.scope);
					//备注
					$('#chain_content').val(union_info.content);
					
					//检查用户是否在该联盟
					if(in_this_union == 2){//不在该联盟
						//显示申请加入联盟
						$('#union_apply').show();
						$('#union_item').show();
					}else{
						//如果联盟主是自己
						if(union_info.agent_id == agent_info.id){
							$('#item_manage').show();
							if(union_info.status == 2){
								$('#back_union_main').show();
							}else{
								$('#union_state').show();
							}
							//判断联盟审核是否通过
						}else{
							if(in_apply == 1 || in_apply ==3){
								$('#apply_state').show();
							}else if(in_apply == 2){
								$('#back_union').show();
							}
							$('#union_item').show();
							
						}
					}
				}else{
					layer.msg(data.msg, {
						  time: 2000 
						}, function(){
							location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
						});
				}
			}
		});
		
		//成员列表
		$('#union_item').click(function(){
			location.href = APP.web_root+'shopwallet/fjysq_memlist.html?union_id='+getUrlParam("union_id");
		})
		//成员管理
		$('#item_manage').click(function(){
			location.href = APP.web_root+'shopwallet/fjysq_memedit.html?union_id='+getUrlParam("union_id");
		});
		
		//申请加入联盟  union_id
		$('#union_apply').click(function(){
			$.ajax({
				url: APP.api_url + 'wallet/union_apply',
				data: {
					token		: get_token(),
					uid			: getUid(),
					union_id	: getUrlParam("union_id")
				},
				success: function(data) {
					if(data.code == 200) {
						layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
					}else{
						layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
					}
				}
			});
		})
		
	})
	//联盟主退出联盟
		$('#back_union_main').click(function(){
			$.ajax({
				url: APP.api_url + 'wallet/back_union',
				data: {
					token		: get_token(),
					uid			: getUid(),
				},
				success: function(data) {
					layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
				}
			});
		});
		//成员退出联盟
		$('#back_union').click(function(){
			$.ajax({
				url: APP.api_url + 'wallet/remove_member',
				data: {
					token		: get_token(),
					uid			: getUid(),
					agent_id	:$("#cut_agent_id").val(),
					union_id	:getUrlParam("union_id")
				},
				success: function(data) {
					layer.msg(data.msg, {
							  time: 2000 
							}, function(){
								location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
							});
				}
			});
		});
	
</script>